using System.Collections.Generic;
using AjaxPro;
using NExt.Serialization.AjaxPro.Conversion;
using NExt.Serialization.Core;
namespace NExt.Serialization.AjaxPro
{
    public class AjaxProSerializer : IJsonSerializer
    {
        public AjaxProSerializer()
        {
            JavaScriptDeserializer.RegisterImplimentationType(typeof(IList<>), typeof(List<>));
            Utility.RegisterConverterForAjax(new ScriptJavaScriptConvertor());
            Utility.RegisterConverterForAjax(new AnonymousObjectJavaScriptConvertor());
            Utility.RegisterConverterForAjax(new ExtJavaScriptConvertor());
        }

        public string Serialize(object instance)
        {
            string result = JavaScriptSerializer.Serialize(instance);
            return result;
        }

        public T Deserialize<T>(string json)
        {
            T instance = JavaScriptDeserializer.DeserializeFromJson<T>(json);
            return instance;
        }

        public object Deserialize(string json, System.Type type)
        {
            object instance = JavaScriptDeserializer.DeserializeFromJson(json, type);
            return instance;
        }
    }
}